unit uFrmPrintCageClose;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, gnugettext, ExtCtrls, Oracle, StdCtrls;

type
  TFrmPrintCageClose = class(TForm)
    stg_Inventory: TStringGrid;
    OracleQuery1: TOracleQuery;
    img_Logo: TImage;
    lbl_TournamentName: TLabel;
    Label1: TLabel;
    stg_Tournaments: TStringGrid;
    Label2: TLabel;
    lbl_Inventory: TLabel;
    stg_CashGames: TStringGrid;
    Label3: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure SetData(CageCloseId: string; OraSession: TOracleSession);
  end;

var
  FrmPrintCageClose: TFrmPrintCageClose;

implementation

uses umainutils, ufrmmain, UUTILS;
{$R *.dfm}

procedure TFrmPrintCageClose.FormClick(Sender: TObject);
begin
  close();
end;

procedure TFrmPrintCageClose.FormCreate(Sender: TObject);
begin
  gnugettext.TranslateComponent(self);
end;

procedure TFrmPrintCageClose.SetData(CageCloseId: string; OraSession: TOracleSession);
var
  i: integer;
  InventorySum: double;
begin
  i := 0;
  InventorySum := 0;
  OracleQuery1.Session := OraSession;
  img_Logo.Picture := UUTILS.GetImage('select IMAGE, IMAGE_TYPE from SETTINGS where id=1', OraSession);
  img_Logo.Picture := FrmMain.img_LogoSettings.Picture;
  OracleQuery1.close;
  OracleQuery1.SQL.Text := 'SELECT * FROM GET_LAST_CAGE_INVENTORIES WHERE ID=' + CageCloseId + ' OR ID=' + CageCloseId + '-1';
  OracleQuery1.Execute;
  while not OracleQuery1.Eof do
  begin
    if OracleQuery1.Field('OPENING') = '1' then
    begin
      stg_Inventory.Cells[1, i] := 'OPENING';
      InventorySum := InventorySum + OracleQuery1.Field('INVENTORY') * -1;
    end
    else
    begin
      stg_Inventory.Cells[1, i] := 'CLOSING';
      InventorySum := InventorySum + OracleQuery1.Field('INVENTORY');
    end;
    stg_Inventory.Cells[0, i] := OracleQuery1.Field('DATETIME');
    stg_Inventory.Cells[2, i] := OracleQuery1.Field('INVENTORY');
    inc(i);
    OracleQuery1.Next;
  end;
  lbl_Inventory.Caption := FloatToStr(InventorySum) + ' ' + Currency_Symbol;
  stg_Inventory.RowCount := i;
  // -------------------------
  OracleQuery1.close;
  OracleQuery1.SQL.Text :=
    'SELECT * FROM GET_CAGE_TOUR_DATA_FROM_OP UNION ALL SELECT NULL, NULL, SUM(BUY_IN), SUM(FEE), SUM(PAY_VALUE), SUM(REBUY_VALUE) AS REBUY_VALUE, SUM(ADDON_VALUE), SUM(TOTAL) FROM GET_CAGE_TOUR_DATA_FROM_OP';
  OracleQuery1.Execute;
  FrmMain.SetGridData(stg_Tournaments, OracleQuery1, false);
  stg_Tournaments.Row := 0;
  stg_Tournaments.ColWidths[0] := 100;
  // -------------------------
  OracleQuery1.close;
  OracleQuery1.SQL.Text :=
    'SELECT * FROM GET_CAGE_CASH_DATA_FROM_OP UNION ALL SELECT NULL, NULL, SUM(INPUT_VALUE), SUM(RAKE_VALUE), SUM(OUTPUT_VALUE), SUM(REBUY_VALUE) AS REBUY_VALUE, SUM(TOTAL) FROM GET_CAGE_CASH_DATA_FROM_OP';
  OracleQuery1.Execute;
  FrmMain.SetGridData(stg_CashGames, OracleQuery1, false);
  stg_CashGames.Row := 0;
  stg_CashGames.ColWidths[0] := 100;
  // --------------------------
  show();
  self.Repaint;
end;

end.
